/* GUI CONVERTED from ppbdova.p (converter v1.76) Thu Jul 18 22:45:13 2002 */
/* ppbdova.p - BURDEN/OVERHEAD COST UPDATE SUBPROGRAM                         */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Revision: 1.11.1.10 $                                                      */
/*V8:ConvertMode=Report                                                       */
/* REVISION: 7.0      LAST MODIFIED: 09/04/91   BY: pma *F003*                */
/*                                   08/17/91   BY: pma *F857*                */
/* REVISION: 7.3      LAST MODIFIED: 02/22/93   BY: pma *G032*                */
/*                                   08/25/93   BY: pxd *GE47*                */
/*                                   06/09/94   BY: rmh *FO61*                */
/*                                   08/27/94   BY: rxm *GL58*                */
/* REVISION: 7.5      LAST MODIFIED: 09/23/94   BY: pma *H535*                */
/* REVISION: 7.5      LAST MODIFIED: 10/18/94   BY: mwd *J034*                */
/* REVISION: 7.2      LAST MODIFIED: 10/27/94   BY: pxd *FS83*                */
/* REVISION: 7.2      LAST MODIFIED: 10/28/94   BY: ais *FS49*                */
/* REVISION: 7.4      LAST MODIFIED: 03/07/95   by: srk *G0GN*                */
/* REVISION: 8.5      LAST MODIFIED: 09/05/95   by: srk *J07G*                */
/* REVISION: 8.5      LAST MODIFIED: 09/21/95   by: wep *J054*                */
/* REVISION: 8.6      LAST MODIFIED: 09/24/97   by: jpm *K0JT*                */
/* REVISION: 8.6e     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane          */
/* REVISION: 8.6e     LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan         */
/* REVISION: 8.6e     LAST MODIFIED: 06/08/98   BY: *K1RZ* Ashok Swaminathan  */
/* REVISION: 8.6e     LAST MODIFIED: 10/12/98   BY: *J322* Santhosh Nair      */
/* REVISION: 9.1      LAST MODIFIED: 09/14/99   BY: *N01B* Poonam Bahl        */
/* REVISION: 9.1      LAST MODIFIED: 10/07/99   BY: *J3LQ* Vivek Gogte        */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00   BY: *N08T* Annasaheb Rahane   */
/* REVISION: 9.1      LAST MODIFIED: 07/19/00   BY: *N0GF* Mudit Mehta        */
/* REVISION: 9.1      LAST MODIFIED: 08/13/00   BY: *N0KQ* myb                */
/* Old ECO marker removed, but no ECO header exists *F0PN*                    */
/* Revision: 1.11.1.7       BY: Katie Hilbert    DATE: 02/25/02  ECO: *N194*  */
/* Revision: 1.11.1.8       BY: Samir Bavkar     DATE: 04/12/02  ECO: *P000*  */
/* $Revision: 1.11.1.10 $    BY: Mark Christian   DATE: 06/04/02  ECO: *N1KH*  */

/* HK 1.0             LAST MODIFIED: 05/10/06   BY: Tony                      */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

/* INCLUDE FILE FOR TITLE AND DEFINED VARIABLES */

/*GUI preprocessor directive settings */
&SCOPED-DEFINE PP_GUI_CONVERT_MODE REPORT
{mfdtitle.i "2+ "}

/* PREPROCESSOR USED FOR REPORTS WITH SIMULATION OPTION */
&SCOPED-DEFINE simulation  true

/* INPUT PARAMETER */
define input parameter transtype as character no-undo.
/* LOCAL VARIABLE DEFINITIONS */
define variable global_costsim  like sc_sim                          no-undo.
define variable global_category like sc_category                     no-undo.
define variable line            like pt_prod_line                    no-undo.
define variable line1           like pt_prod_line                    no-undo.
define variable part            like pt_part                         no-undo.
define variable part1           like pt_part                         no-undo.
define variable type            like pt_part_type                    no-undo.
define variable type1           like pt_part_type                    no-undo.
define variable pm_code         like pt_pm_code                      no-undo.
define variable mtl_percent     as   decimal format "->>>,>>9.99< %"
                                           label "Material"          no-undo.
define variable lbr_percent     as   decimal format "->>>,>>9.99< %"
                                           label "Labor"             no-undo.
define variable bdn_percent     as   decimal format "->>>,>>9.99< %"
                                           label "Burden"            no-undo.
define variable sub_percent     as   decimal format "->>>,>>9.99< %"
                                           label "Subcontract"       no-undo.
define variable ovh_percent     as   decimal format "->>>,>>9.99< %"
                                           label "Overhead"          no-undo.
define variable new_tl          like sct_bdn_tl                      no-undo.
define variable cur_label       as   character format "x(4)"         no-undo.
define variable star            as   character format "x(1)"
                                               initial "*"           no-undo.
define variable site            like si_site                         no-undo.
define variable fromset         like cs_set                          no-undo.

define variable site1            like si_site                         no-undo.  
define variable toset         like cs_set                          no-undo.
/* RENAMED VARIABLE TO UPDATE_YN FROM UPDT_YN TO MAINTAIN     */
/* CONSISTENCY BETWEEN REPORTS WITH SIMULATION OPTION         */
define variable update_yn     like mfc_logical label "Update"        no-undo.
define variable oldcst        like sct_cst_tot                       no-undo.
define variable element       like spt_element                       no-undo.
define variable usr_val       as   character   format "x(12)"
                                               extent 5              no-undo.
define variable usr_elm       like   sc_element
                                                 extent 5            no-undo.
define variable thislvl_yn    like   mfc_logical initial yes
                              label  "Use This/Lower Level Costs"
                              /* format "This Level/Lower Level"  */      no-undo.
define variable rndmthd       like   gl_rnd_mthd                     no-undo.

define variable add_replace   like  mfc_logical /* format "Replace/Add" */
                              label "Replace/Add To Existing Cost"
                              initial yes                            no-undo.
define variable l_err_num     as    integer                          no-undo.

/* DECLARATIONS FOR gpglef.i */
{gpglefdf.i}
{gldynrm.i new}
/* POPULATES VARIABLES usr_val AND usr_elm FROM TABLE lngd_det */
run populate-usr-vars.

/* SELECT FORM */

/*GUI preprocessor Frame A define */
&SCOPED-DEFINE PP_FRAME_NAME A

FORM /*GUI*/ 
   
 RECT-FRAME       AT ROW 1 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1 COLUMN 3 NO-LABEL VIEW-AS TEXT SIZE-PIXELS 1 BY 1
 SKIP(.1)  /*GUI*/
line          colon 20 line1 label {t001.i} colon 49
   part          colon 20 part1 label {t001.i} colon 49
   type          colon 20 type1 label {t001.i} colon 49
   pm_code       colon 20 skip(1)
   site          colon 20 fromset colon 35    site1     colon 49 toset colon 64 skip(1)
   mtl_percent   colon 20  element colon 49
   lbr_percent   colon 20 skip
   bdn_percent   colon 20 skip
   ovh_percent   colon 20
   sub_percent   colon 20 skip(1)
   add_replace   colon 35
   /* thislvl_yn    colon 35 */
   update_yn     colon 68
with frame a side-labels width 80 attr-space NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-a-title AS CHARACTER INITIAL "".
 RECT-FRAME-LABEL:SCREEN-VALUE in frame a = F-a-title.
 RECT-FRAME-LABEL:HIDDEN in frame a = yes.
 RECT-FRAME:HEIGHT-PIXELS in frame a =
  FRAME a:HEIGHT-PIXELS - RECT-FRAME:Y in frame a - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME a = FRAME a:WIDTH-CHARS - .5.  /*GUI*/

/*GUI preprocessor Frame A undefine */
&UNDEFINE PP_FRAME_NAME



/* SET EXTERNAL LABELS */
setFrameLabels(frame a:handle).

/* DETAIL FORM */
FORM /*GUI*/ 
   pt_part     format "x(25)"
   cur_label   no-label
   sct_mtl_tl
   sct_lbr_tl
   sct_sub_tl
   sct_ovh_tl
   sct_bdn_tl
   sct_cst_tot
   pt_um
   star        no-label
with STREAM-IO /*GUI*/  frame det2 width 132 no-attr-space no-box.

/* SET EXTERNAL LABELS */
setFrameLabels(frame det2:handle).

FORM /*GUI*/ 
   header
   space(60)
   fromset
with STREAM-IO /*GUI*/  frame c_cost width 132 no-attr-space page-top no-box.

FORM /*GUI*/ 
   header
   skip(1)
with STREAM-IO /*GUI*/  frame skip1 page-top.

for first icc_ctrl
   fields(icc_cogs icc_gl_sum icc_gl_tran icc_mirror
          icc_jrnl icc_cur_set icc_gl_set)
   no-lock:
end. /* FOR FIRST icc_ctrl */

for first gl_ctrl
   fields(gl_rnd_mthd)
   no-lock:

   rndmthd = gl_rnd_mthd.
end. /* FOR FIRST gl_ctrl */

assign  /*tony*/
   fromset        = icc_cur_set
   global_costsim = fromset
   site           = global_site.

if transtype = "PPBDN"
then
   assign
      bdn_percent     = 100
      ovh_percent     = 0
      element         = usr_elm[3]
      global_category = "3".
else
if transtype = "PPOVH"
then
   assign
      bdn_percent     = 0
      ovh_percent     = 100
      element         = usr_elm[4]
      global_category = "4".
 
if transtype = "PPMTL"    /*tony*/
THEN
    ASSIGN
     mtl_percent     = 100
     lbr_percent     = 100
     bdn_percent     = 100
     ovh_percent     = 100
     sub_percent     = 100
     element         = usr_elm[1]
     global_category = "1".
    .



assign
   cur_label      = " " + getTermLabel("OLD",3)
   fromset        = icc_cur_set
   global_costsim = fromset
   site           = global_site
   pm_code= 'M'.

/* REPORT BLOCK */
repeat:

   if part1 = hi_char  then part1 = "".
   if line1 = hi_char  then line1 = "".
   if type1 = hi_char  then type1 = "".

   update
      line
      line1
      part
      part1
      type
      type1
      pm_code
      site
      fromset
      site1
      toset
      mtl_percent
      lbr_percent
      bdn_percent
      ovh_percent
      sub_percent
      element
      add_replace
      /*thislvl_yn*/
      update_yn
   with frame a
   editing:
      global_costsim = input fromset.
      readkey.
      apply lastkey.
   end. /* UPDATE WITH FRAME a EDITING */

   /* VALIDATES THE SITE */
   run site_validation
       (input  site,
        input  global_db,
        input  batchrun,
        output l_err_num,
        buffer si_mstr).

   if l_err_num <> 0
   then do:
      {pxmsg.i &MSGNUM=l_err_num &ERRORLEVEL=3}
      next-prompt site with frame a.
      undo, retry.
   end. /* IF l_err_num */



   if  fromset = ""
   then do:
      /* BLANK NOT ALLOWED */
      {pxmsg.i &MSGNUM=40 &ERRORLEVEL=3}
      next-prompt fromset with frame a.
      undo, retry.
   end. /* IF FROMSET = "" */

   for first cs_mstr
      fields (cs_set cs_type)
      where cs_set = fromset
      no-lock:
   end. /* FOR FIRST cs_mstr */

   if not available cs_mstr
   then do:
      /* COST SET DOES NOT EXIST */
      {pxmsg.i &MSGNUM=5407 &ERRORLEVEL=3}
      next-prompt fromset with frame a.
      undo, retry.
   end. /* IF NOT AVAILABLE cs_mstr */

   run site_validation   /*tony*/
       (input  site1,
        input  global_db,
        input  batchrun,
        output l_err_num,
        buffer si_mstr).

   if l_err_num <> 0
   then do:
      {pxmsg.i &MSGNUM=l_err_num &ERRORLEVEL=3}
      next-prompt site1 with frame a.
      undo, retry.
   end. /* IF l_err_num */

   if  toset = ""
   then do:
      /* BLANK NOT ALLOWED */
      {pxmsg.i &MSGNUM=40 &ERRORLEVEL=3}
      next-prompt toset with frame a.
      undo, retry.
   end. /* IF FROMSET = "" */

   for first cs_mstr
      fields (cs_set cs_type)
      where cs_set = toset
      no-lock:
   end. /* FOR FIRST cs_mstr */

   if not available cs_mstr
   then do:
      /* COST SET DOES NOT EXIST */
      {pxmsg.i &MSGNUM=5407 &ERRORLEVEL=3}
      next-prompt toset with frame a.
      undo, retry.
   end. /* IF NOT AVAILABLE cs_mstr */



   for first sc_mstr
      fields (sc_category sc_element sc_sim)
      where sc_sim     = /*fromset*tony*/ toset
      and   sc_element = element
      no-lock:

      if transtype = "PPBDN"
      then do:

         if sc_category <> "3"
         then do:
            /* ONLY # COST ELEMENTS ARE ALLOWED */
            {pxmsg.i &MSGNUM=5305 &ERRORLEVEL=3 &MSGARG1=usr_val[3]}
            next-prompt element with frame a.
            undo, retry.
         end. /* IF sc_category <> "3" */

      end. /* IF transtype = "PPBDN" */
      else
      if transtype = "PPOVH"
      then do:

         if sc_category <> "4"
         then do:
            /* ONLY # COST ELEMENTS ARE ALLOWED */
            {pxmsg.i &MSGNUM=5305 &ERRORLEVEL=3 &MSGARG1=usr_val[4]}
            next-prompt element with frame a.
            undo, retry.
         end. /* IF sc_category <> "4" */

      end. /* ELSE IF transtype = "PPBDN" */

   end. /* FOR FIRST sc_mstr */

   if not available sc_mstr
   then do:
      /* ELEMENT NOT DEFINED */
      {pxmsg.i &MSGNUM=103 &ERRORLEVEL=3}
      next-prompt element with frame a.
      undo, retry.
   end. /* IF NOT AVAILABLE sc_mstr */

   /* SECTION ADDED TO VERIFY GL IS OPEN */
   if update_yn
   then do:

      if cs_type = 'gl'
      then do:

         assign
            gl_trans_type = "IC"
            gl_trans_ent  = si_entity
            gl_effdt_date = today.

         /* REPLACED SECOND PARAMETER FROM glentity TO gl_trans_ent TO    */
         /* PICK TRANSACTION ENTITY INSTEAD OF SYSTEM'S PRIMARY ENTITY    */
         {gprun.i ""gpglef.p""
            "(input  gl_trans_type,
              input  gl_trans_ent,
              input  gl_effdt_date,
              input  1,
              output gpglef )" }

         if gpglef > 0
         then do:
            next-prompt fromset with frame a.
            undo, retry.
         end. /* IF gpglef > 0 */

      end. /* IF cs_type = 'gl' */

   end. /* IF update_yn */

   /* END OF CODE ADDED TO VERIFY GL IS OPEN */

   bcdparm = "".

   /* REPLACES MULTIPLE CALLS TO mfquoter.i */
   {gprun.i ""gpquote.p""
      "(input-output bcdparm,
        18,
        line,
        line1,
        part,
        part1,
        type,
        type1,
        pm_code,
        site,
        fromset,
        element,
        string(mtl_percent),
        string(lbr_percent),
        string(bdn_percent),
        string(ovh_percent),
        string(sub_percent),
        string(add_replace),
        string(thislvl_yn),
        string(update_yn),
        null_char,
        null_char)"}

   if part1 = "" then part1 = hi_char.
   if line1 = "" then line1 = hi_char.
   if type1 = "" then type1 = hi_char.

   /* OUTPUT DESTINATION SELECTION */
   {gpselout.i &printType                = "printer"
               &printWidth               = 132
               &pagedFlag                = " "
               &stream                   = " "
               &appendToFile             = " "
               &streamedOutputToTerminal = " "
               &withBatchOption          = "yes"
               &displayStatementType     = 1
               &withCancelMessage        = "yes"
               &pageBottomMargin         = 6
               &withEmail                = "yes"
               &withWinprint             = "yes"
               &defineVariables          = "yes"}
/*GUI*/ RECT-FRAME:HEIGHT-PIXELS in frame a = FRAME a:HEIGHT-PIXELS - RECT-FRAME:Y in frame a - 2.


   /* INCLUDE FILE TO PRINT PAGE HEADING FOR REPORTS */
   {mfphead.i}

   view frame c_cost.

   view frame skip1.

   loopb:
   for each pt_mstr
      fields (pt_desc1   pt_part      pt_part_type
              pt_pm_code pt_prod_line pt_site
              pt_um)
      where pt_part      >= part
      and   pt_part      <= part1
      and   pt_prod_line >= line
      and   pt_prod_line <= line1
      and   pt_part_type >= type
      and   pt_part_type <= type1
      no-lock
      transaction with frame det2:

      if page-size - line-counter < 2
      then
         page.

      /* ADDED CONDITION TO AVOID CREATION OF COST SET RECORDS FOR */
      /* ITEMS WHICH DON'T HAVE COST SET RECORD FOR SITE AND COST  */
      /* SET COMBINATION                                           */
      if not (can-find (first sct_det
                           where sct_sim  = fromset
                           and   sct_part = pt_part
                           and   sct_site = site
                           no-lock))
      then
         next loopb.



      for first ptp_det
         fields (ptp_part ptp_pm_code ptp_site)
         where ptp_part = pt_part
         and   ptp_site = site
         no-lock:
      end. /* FOR FIRST ptp_det */

      if (available ptp_det
         and ptp_pm_code <> pm_code
         and pm_code     <> "")
         or (not available ptp_det
         and pt_pm_code  <> pm_code
         and pm_code     <> "")
      then
         next loopb.

/*tony */
      if not (can-find (first sct_det
                           where sct_sim  = toset
                           and   sct_part = pt_part
                           and   sct_site = site1
                           no-lock))
      then
         next loopb.
/*tony*/


      /* RETURN NEW COST SET (SCT_DET) RECORD */
      {gpsct08.i &set=fromset &part=pt_part &site=site}

      assign
         new_tl = 0.
 /* tony        oldcst = sct_cst_tot.
*/
      display
         pt_part
            + fill(" ",21 - length(pt_part))
            + getTermLabel("OLD",3) @ pt_part
         " "
            + getTermLabel("THIS_LEVEL",3) @ cur_label
         sct_mtl_tl
         sct_lbr_tl
         sct_bdn_tl
         sct_ovh_tl
         sct_sub_tl
         sct_cst_tot
         pt_um
      with down frame det2 STREAM-IO /*GUI*/ .

      down 1.

      display
         " "
            + pt_desc1 @ pt_part
         " "
            + getTermLabel("LOWER_LEVEL",3) @ cur_label
         sct_mtl_ll @ sct_mtl_tl
         sct_lbr_ll @ sct_lbr_tl
         sct_bdn_ll @ sct_bdn_tl
         sct_ovh_ll @ sct_ovh_tl
         sct_sub_ll @ sct_sub_tl
      with down frame det2 STREAM-IO /*GUI*/ .

    /*  if thislvl_yn
      then */
         new_tl =  sct_mtl_tl * mtl_percent / 100
                +  sct_lbr_tl * lbr_percent / 100
                +  sct_bdn_tl * bdn_percent / 100
                +  sct_ovh_tl * ovh_percent / 100
                +  sct_sub_tl * sub_percent / 100.
  /*    else */
         new_tl = new_tl + sct_mtl_ll * mtl_percent / 100
                +  sct_lbr_ll * lbr_percent / 100
                +  sct_bdn_ll * bdn_percent / 100
                +  sct_ovh_ll * ovh_percent / 100
                +  sct_sub_ll * sub_percent / 100.

      if new_tl < 0
      then
         new_tl = 0.

      /* UPDATES THE NEW COST */
  /* tony   */      {gpsct08.i &set=toset &part=pt_part &site=site1}
	        assign
       
 /* tony   */     oldcst = sct_cst_tot.
 
      run update_cost
          (input  element,
           input  sc_category,
           input  new_tl,
           input  add_replace,
           buffer sct_det).

      down 1.

      display
         fill(" ",21) + getTermLabel("NEW",3) @ pt_part
         " " + getTermLabel("THIS_LEVEL",3) @ cur_label
         sct_mtl_tl
         sct_lbr_tl
         sct_bdn_tl
         sct_ovh_tl
         sct_sub_tl
         sct_cst_tot
         star when (oldcst <> sct_cst_tot)
      with down frame det2 STREAM-IO /*GUI*/ .

      down 1.

      display
         " " + getTermLabel("LOWER_LEVEL",3) @ cur_label
         sct_mtl_ll @ sct_mtl_tl
         sct_lbr_ll @ sct_lbr_tl
         sct_bdn_ll @ sct_bdn_tl
         sct_ovh_ll @ sct_ovh_tl
         sct_sub_ll @ sct_sub_tl
      with down frame det2 STREAM-IO /*GUI*/ .

      down 2.

      if not update_yn
      then
         undo loopb, next loopb.

      /* CREATES INVENTORY GL TRANSACTIONS WHEN STD. COST IS CHANGED */
      run create_inv_gl_trans
          (input  oldcst,
           input  site1,
           input  rndmthd,
           output trmsg,
           buffer sct_det,
           buffer icc_ctrl,
           buffer pt_mstr).

      /* REPORT EXIT FOR PAGING INCLUDE FILE */
      
/*GUI*/ {mfguichk.i } /*Replace mfrpchk*/


   end.  /* loopb */

   /* REPORT TRAILER */
   {mfrtrail.i}

end. /* REPEAT */

/* CREATED TO KEEP CODE COMMON TO ppbdova.p AND ppbdov3a.p IN ONE PLACE */
{ppbdov.i}

PROCEDURE populate-usr-vars:
/*-------------------------------------------------------------------------
Purpose   : Populate usr_val and usr_elm from lngd_det
Parameters: none
Notes     : Added this procedure with patch /*K0JT*/
--------------------------------------------------------------------------*/

   for each lngd_det
       fields (lngd_dataset lngd_field lngd_key1
               lngd_key2    lngd_key3  lngd_key4
               lngd_lang    lngd_translation)
       where lngd_dataset = "sc_mstr"
       and   lngd_key1    = ""
       and   lngd_key2    = ""
       and   lngd_key3    = ""
       and   lngd_field   = "sc_category"
       and   lngd_lang    = global_user_lang
       no-lock:

       assign
          usr_val[integer(lngd_key4)] = lngd_translation
          usr_elm[integer(lngd_key4)] = substring(lngd_translation,1,8).

   end. /* FOR EACH lngd_det */

END PROCEDURE.
